<?php 
class Unit_model extends CI_Model {  

    function Unit_model()
    {
        // Call the Model constructor
        parent::__construct();
    }

	function getUnit($cabang = NULL) # get unit from table unit in database
	{
		$this -> db -> select('*');
		$this -> db -> from('unit');
		$this -> db -> order_by('nama_unit','asc');

		if($this -> data['kode_privilege'] == '0') {
			# do nothing...
		} else if( ! is_null($cabang)){
			$this -> db -> where('kode_cabang', $cabang);
		} else {
			$this -> db -> where('kode_cabang !=', '000');
		}
		
		$query = $this -> db -> get();

		if($query -> num_rows() > 0)
		{
			return $query->result();
		}
		else
		{
			return show_error('Database is empty!');
		}
	}


    function getMember()
	{
		$this -> db -> select('*');
		$this -> db -> from('unit');

		$this -> db -> order_by('nama_unit','asc');

		$query = $this -> db -> get();

		if($query -> num_rows() > 0)
		{
			return $query->result();
		}
		else
		{
			return show_error('Database is empty!');
		}
	}
}  
?>